<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>报表展示</title>
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/js/jquery-2.1.4.js"></script>
    <script type="text/javascript" src="/js/funs.js"></script>
    <script type="text/javascript" src="/js/echarts.js"></script>
    <style>
        #container {
            display: flex;
            justify-content: space-between;
        }

        #main1 {
            flex: 1;
            width: 600px;
            height: 400px;
        }

        #main2 {
            flex: 1;
            width: 600px;
            height: 400px;
        }
    </style>
</head>
<body>
<div id="container">
    <div id="main1"></div>
    <div id="main2"></div>
</div>

<script type="text/javascript">
    var myChart1 = echarts.init(document.getElementById('main1'));
    var myChart2 = echarts.init(document.getElementById('main2'));

    $.post('/echarts/select',
        function(result){
            console.log(result.data);
        let data=result.data;
            let xArray = new Array();
            let yArray = new Array();
            for (let i = 0; i < data.length; i++) {
                xArray.push(data[i].name);
                yArray.push(data[i].value);
            }


            var option1 = {
                title: {
                    text: 'ECharts 入门示例'
                },
                tooltip: {},
                legend: {
                    data: ['销量']
                },
                xAxis: {
                    data: xArray
                },
                yAxis: {},
                series: [
                    {
                        name: '销量',
                        type: 'bar',
                        data: yArray
                    }
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart1.setOption(option1);


            //饼状图
            let option2 = {
                title: {
                    text: 'Referer of a Website',
                    subtext: 'Fake Data',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: '50%',
                        data: data,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            myChart2.setOption(option2);
        },
        'json'
    );
</script>
</body>
</html>